#pragma once

#include <windows.h>

#include "collection.h"
#include "window.h"

/** 
 * \ingroup ti6
 *
 * \brief
 * The CollectionBox class represents a control used to show a collection.
 * The control is added to MainWindow and is responsible for drawing
 * the thumbnails on the screen, and to provide the functionality to
 * select one of them. When the user clicks a thumbnail, the CollectionBox
 * instance will detect this and change the selection in the Collection
 * instance.
 *
 * Copyright (c) Academie voor ICT en Media 2007 - 2008
 */
class CollectionBox: public Window
{
public:
	/**
	 \brief
	 Default constructor. Use create() to initialize the instance.
	 */
	CollectionBox();

	/**
	 \brief
	 Deconstructor. This does not delete the Collection instance.
	 */
	~CollectionBox();

	/**
	 \brief
	 Set the position of the collection box.
	 
	 \param rect The rectangle which identifies the position and size of the window.
	 \param repaint Identifies whether the window should be repainted.
	 \return TRUE is returned if the position is successfully set. In case of
	   an error, FALSE is returned.
	 */
	BOOL setPosition( RECT rect, BOOL repaint = TRUE );

	/**
	 \brief
	 Set the visibility of the window.
	 
	 \param nCmdShow SW_SHOW to show the window, SW_HIDE to make the window
	   invisible.
	 */
	void show( int nCmdShow = SW_SHOW );

	/**
	 \brief
	 Get the collection which is currently showed.
	 
	 \return A pointer to the collection.
	 */
	Collection* collection() const;

	/**
	 \brief
	 Set the collection to show. The CollectionBox instance does not take
	 ownership of the collection.
	 
	 \param *collection A pointer to the collection.
	 */
	void setCollection( Collection *collection );

	/**
	 \brief
	 Initialize the instance. This will register the window class if
	 neccesary and create the window itself.
	 
	 \param hWndParent Handle to the parent window.
	 \param hInstance Instance handle.
	 \return True is returned if the window is successfully created. In
	   case of an error, false is returned.
	 */
	bool create( HWND hWndParent, HINSTANCE hInstance );

	/**
	 \brief
	 Handle messages, specific for this window.
	 
	 \param uMsg The message id.
	 \param wParam 32 bits value, specific to the message.
	 \param lParam 32 bits value, specific to the message.
	 \return The result of the processing, which is dependent on the type of message.
	 */
	virtual LRESULT handleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam );

	/**
	 \brief
	 Get a handle to the window. Do not close this handle.

	 \return A handle to this window.
	 */
	HWND hWnd() const;

private:
	/**
	 \brief
	 Register the window class. This is a 'template' for windows which
	 is registered in the kernel. The window class for collection boxes is
	 registered under the name "CollectionBox".

	 \param hInstance The instance handle.
	 \return If the window class is successfully registered, true is
	   returned. False is returned in case of an error.
	 */
	static bool registerWndClass( HINSTANCE hInstance );

	/**
	 A pointer to the collection to show. This instance does not have
	 ownership of the collection.
	 */
	Collection *_collection;

	/**
	 A handle to the window.
	 */
	HWND _hWnd;

	/**
	 The window class.
	 */
	static ATOM _wndClass;
};
